package 一些基础的数据结构;

import java.util.LinkedList;
import java.util.Queue;

public class TwoQueuesImplementStack {
    public static class TwoQueueStack<T>{
        public Queue<T> queue;
        public Queue<T> help;

        public TwoQueueStack(){
            queue = new LinkedList<>();
            help = new LinkedList<>();
        }
        public void push(T value){
            queue.offer(value);
        }
        public T poll(){
            while (queue.size()>1){
                help.offer(queue.poll());
            }
            T ans = queue.poll();
            Queue<T> tmp = queue;
            queue = help;
            help =  queue;
            return ans;
        }
        public T peek(){
            while (queue.size()>1){
                help.offer(queue.poll());
            }
            T ans = queue.poll();
            help.offer(ans);
            Queue<T> tmp = queue;
            queue = help;
            help =  queue;
            return ans;
        }
        public boolean isEmpty(){
            return queue.isEmpty();
        }
    }
}
